package org.aplikator.client.local.widgets;

import com.github.gwtbootstrap.client.ui.Button;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

import org.aplikator.client.local.wizards.WizardSupport;
import org.aplikator.client.local.wizards.WizardSupportCallbacks;
import org.aplikator.client.shared.descriptor.FunctionDTO;
import org.aplikator.client.shared.descriptor.FunctionWidgetDTO;
import org.aplikator.client.shared.descriptor.WizardPageDTO;

public class FunctionButtonWidget extends Button implements WizardSupportCallbacks {

    private WizardSupport wizardSupport;
    
    
    public FunctionButtonWidget(final FunctionDTO function, final HasFields containingForm) {
        this.wizardSupport = new WizardSupport(function, containingForm, this);
        
        containingForm.registerFunctionButton(this);
        this.setText(function.getLocalizedName());

        this.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                wizardSupport.changePageRequest(true);
            }
        });
    }


    @Override
    public void wizardPageCallback(WizardPageDTO response, boolean forw) {
    }

    @Override
    public void runBeforeFunctionCallback() {
        this.setEnabled(false);
    }

    @Override
    public void runAfterFunctionCallback() {
        this.setEnabled(true);
    }
}
